<?php
include "config.php";
$objDB = new pgsql();

$uid		= $_REQUEST['uid'] ? $_REQUEST['uid'] : 0;
$userno		= $_REQUEST['uno'];
$uname		= $_REQUEST['username'];
$authKey	= $_REQUEST['fbauthkey'];


$sql	= "SELECT uid FROM member WHERE uid = $uid or userno = '$userno'";
$objDB->query($sql);
$rowCnt	= $objDB->numrows();
if($rowCnt > 0) {

	$uidArr	= $objDB->fetch();
	$userid = $uidArr[0]['uid'];
	$sql = "UPDATE member set fbauthkey = '$authKey' where userno = '$userno'";
	if($objDB->query($sql)) {
		echo $userid;///< 이미 등록되어있는 사용자;
	}
} else {
	$sql = "SELECT nextval('member_mid_seq')";
	$objDB->query($sql);
	$tidArr = $objDB->fetch();

	$userid = $tidArr[0]['nextval'];
	$sql = "INSERT INTO member (uid, usertype, userno, username, fbauthkey, rdate) VALUES($userid, 1, '$userno', '$uname', '" . $authKey . "', now())";///<logtype = 1은 Facebook
	if($objDB->query($sql)) {
		echo $userid;
	} else {
		echo 0;
	}
}
//AAAC8ODyCwqoBAOFd5aN685p3696aOfOZBURr3YZCGHyBXn36BC4yLjveEyGCXCJIoHrn4is7Rn5Ie1e8xhBrNzAsy6X2kZD
?>
